﻿#include"Game.h"


void GameStart(int chessBoard[ROL][COL])
{
	InitGame();//初始化
	int choice = 1, choice2;

	 do
	{
		menu();
		printf("请选择：");
		scanf("%d", &choice);
		switch (choice)
		{
		case 1:
			do
			{
				menu1();
				printf("请选择：");
				scanf("%d", &choice2);
				switch (choice2)
				{
				case 1:
					UpDate(chessBoard);//更新界面
					PlayerTurn(chessBoard,White);//玩家回合
					//ComputerTurn(chessBoard);//电脑回合
					UpDate(chessBoard);//更新界面
					break;
				case 0:
					break;
				default:
					printf("输入有误，请重新输入\n");
				}
			} while (choice2);
			break;
		case 0:
			printf("退出游戏！");
			break;
		default:
			printf("输入有误，请重新输入!\n");
		}
	} while (choice);

}
int CheckPos(int x, int y)
{
	if (x < 0 || x > ROL - 1 || y < 0 || y > ROL - 1)
	{
		return 0;
	}
	return 1;
}
int CheckChess(int chessBoard[ROL][COL], int x, int y)
{
	if (chessBoard[x][y] == 0)
	{
		return 1;
	}
	return 0;
}
void SetChess(int chessBoard[ROL][COL],int flg)
{
	int x, y;
	printf("请输入坐标：");
	scanf("%d%d", &x, &y);
	if (!CheckPos(x,y))
	{
		printf("输入坐标非法，请重新输入！\n");
	}
	else
	{
		if (CheckChess(chessBoard,x,y))
		{
			chessBoard[x][y] = flg;
		}
		else
		{
			printf("该位置不可执子！\n");
		}
	}
}
void PlayerTurn(int chessBoard[ROL][COL], int flg)
{
	SetChess(chessBoard, flg);//执棋
}
void menu1()
{
	printf("********************\n");
	printf("******1.执子 *******\n");
	printf("******0.返回 *******\n");
	printf("********************\n");
}
void menu()
{
	printf("********************\n");
	printf("*******五子棋*******\n");
	printf("******1.开始游戏 ***\n");
	printf("******0.退出游戏 ***\n");
	printf("********************\n");
}
void UpDate(int chessBoard[ROL][COL])
{
	PrintBoard(chessBoard);
	//定位鼠标打印提示信息.......
}
void InitGame()
{
	_wsetlocale(LC_ALL, L"chs");
}
void PrintBoard(int chessBoard[ROL][COL])
{
	for (int i = 0; i < ROL; i++)
	{
		if (0 == i)
		{
			for (int j = 0; j < COL; j++)
			{
				if (0 == j)
				{
					Print(chessBoard[i][j], "┌ ");
				}
				else if (COL - 1 == j)
				{
					Print(chessBoard[i][j], "┐ ");
				}
				else
				{
					Print(chessBoard[i][j], "┬ ");
				}
			}
			printf("\n");
		}
		else if (14 == i)
		{
			for (int j = 0; j < COL; j++)
			{
				if (0 == j)
				{
					Print(chessBoard[i][j], "└ ");
				}
				else if (COL - 1 == j)
				{
					Print(chessBoard[i][j], "┘");
				}
				else
				{
					Print(chessBoard[i][j], "┴ ");
				}
			}
			printf("\n");
		}
		else
		{
			for (int j = 0; j < COL; j++)
			{
				if (0 == j)
				{
					Print(chessBoard[i][j], "├ ");
				}
				else if (COL - 1 == j)
				{
					Print(chessBoard[i][j], "┤ ");
				}
				else
				{
					Print(chessBoard[i][j], "┼ "); //●┼
				}
			}
			printf("\n");
		}
	}
}
void Print(int type, char* wall)
{
	if (type == White)
	{
		wprintf(L"%s", Playerchess);
	}
	if (type == Black)
	{
		wprintf(L"%s",Computerchess);
	}
	if (type == 0)
	{
		printf("%s",wall);
	}
}